#include <bits/stdc++.h>

#define ep emplace
#define eb emplace_back
#define in read()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using vec = vector < int >;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

const int N = 7e4 + 10;

int n, siz[N], son[N], dep[N], d[N], tc[N], pot[N], top, ans[N];
bool vis[N];
vec G[N];
int tval[N << 1], *val = tval + N;
int tl, tr, rt;

int query(int x) { return x < tl ? 0 : x <= tr ? val[x] : val[tr]; }

void fsz(int x, int p) { siz[x] = 1; son[x] = 0; for(auto y : G[x]) if(y ^ p && !vis[y]) fsz(y, x), siz[x] += siz[y], son[x] = max(son[x], siz[y]); }

void frt(int x, int p, int tsz) { for(auto y : G[x]) if(y ^ p && !vis[y]) frt(y, x, tsz); son[x] = max(son[x], tsz - siz[x]); (rt == 0 || son[x] < son[rt]) && (rt = x); }

void init() {
	queue < int > q; rep(i, 1, n) d[i] = 1e9;
	rep(i, 1, n) if(G[i].size() == 1) q.ep(i), d[i] = 0;
	while(q.size()) { int x = q.front(); q.pop(); for(auto v : G[x]) if(d[v] == 1e9) d[v] = d[x] + 1, q.ep(v); }
}

void dfs(int x, int p) { dep[x] = dep[p] + 1; tc[x] = d[x] - dep[x]; pot[++top] = x; for(auto y : G[x]) if(!vis[y] && y ^ p) dfs(y, x); }

void calc(int lst, int top) {
	tl = n, tr = -n;
	rep(i, lst, top) tl = min(tl, tc[pot[i]]), tr = max(tr, tc[pot[i]]);
	rep(i, tl - 1, tr) val[i] = 0; rep(i, lst, top) val[tc[pot[i]]] += 2 - G[pot[i]].size();
	rep(i, tl, tr) val[i] += val[i - 1];
}

void divide(int x) {
	fsz(x, 0); rt = 0; frt(x, 0, siz[x]); x = rt; vis[x] = true;
	dep[x] = top = 0; 
	for(auto y : G[x]) if(!vis[y]) {
			int lst = top + 1; dfs(y, x); calc(lst, top);
			rep(i, lst, top) ans[pot[i]] -= query(dep[pot[i]]);
			//rep(i, lst, top) rep(j, lst, top) if(tc[pot[j]] <= dep[pot[i]]) ans[pot[i]] -= 2 - G[pot[j]].size();
		}
	pot[++top] = x; tc[x] = d[x]; calc(1, top); rep(i, 1, top) ans[pot[i]] += query(dep[pot[i]]);
	//rep(i, 1, top) rep(j, 1, top) if(tc[pot[j]] <= dep[pot[i]]) ans[pot[i]] += 2 - G[pot[j]].size();
	for(auto y : G[x]) if(!vis[y]) divide(y);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 2, n) { int u = in, v = in; G[u].eb(v); G[v].eb(u); }
	init(); divide(1); rep(i, 1, n) printf("%d\n", ans[i] - (G[i].size() == 1));
	return 0;
}
